package com.company.aicrawlers.controller.api;

import com.company.aicrawlers.common.dto.ApiResponse;
import com.company.aicrawlers.entity.CollectResult;
import com.company.aicrawlers.service.CollectResultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采集结果查询 API Controller
 * 
 * @author AI Crawlers
 * @since 2025-10-10
 */
@Slf4j
@RestController
@RequestMapping("/api/collect-results")
public class CollectResultApiController {

    @Autowired
    private CollectResultService collectResultService;

    /**
     * 获取任务的所有采集结果
     * 
     * 接口：GET /api/collect-results/task/{taskId}
     * 
     * @param taskId 任务ID
     * @return 结果列表
     */
    @GetMapping(value = "/task/{taskId}", name = "getResultsByTask")
    public ApiResponse<List<CollectResult>> getByTaskId(@PathVariable("taskId") Long taskId) {
        List<CollectResult> results = collectResultService.getByTaskId(taskId);
        return ApiResponse.success(results);
    }

    /**
     * 对比查询（同一问句多平台）
     * 
     * 接口：GET /api/collect-results/compare
     * 
     * @param taskId 任务ID
     * @param questionId 问句ID
     * @return 结果列表
     */
    @GetMapping(value = "/compare", name = "compareResults")
    public ApiResponse<List<CollectResult>> compareResults(
            @RequestParam("taskId") Long taskId,
            @RequestParam("questionId") Long questionId) {
        List<CollectResult> results = collectResultService.compareResults(taskId, questionId);
        return ApiResponse.success(results);
    }

    /**
     * 删除结果
     * 
     * 接口：DELETE /api/collect-results/{id}
     * 
     * @param id 结果ID
     * @return 成功信息
     */
    @DeleteMapping(value = "/{id}", name = "deleteResult")
    public ApiResponse<Void> deleteResult(@PathVariable("id") Long id) {
        collectResultService.removeById(id);
        return ApiResponse.success("删除成功");
    }
}

